package com.personalkeeper;

import static com.personalkeeper.PersonalKeeper.DATE;
import static com.personalkeeper.PersonalKeeper.DESCRIPTION;
import static com.personalkeeper.PersonalKeeper.ID;
import static com.personalkeeper.PersonalKeeper.IMAGE_PATH;
import static com.personalkeeper.PersonalKeeper.LATITUDE;
import static com.personalkeeper.PersonalKeeper.LONGITUDE;
import static com.personalkeeper.PersonalKeeper.TITLE;

import com.personalkeeper.HistoryProvider.Notes;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;


public class NotesListActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        NotesCursorAdapter adapter = new NotesCursorAdapter(
            this,
            managedQuery(Notes.CONTENT_URI, null, null, null, null));

        setListAdapter(adapter);
    }
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        NotesCursorAdapter.ViewHolder holder = (NotesCursorAdapter.ViewHolder) v.getTag();

        Intent intent = new Intent(this, ShowNoteActivity.class);
        intent.putExtra(ID, holder.id);
        intent.putExtra(LATITUDE, holder.latitude);
        intent.putExtra(LONGITUDE, holder.longitude);
        intent.putExtra(DATE, holder.date);
        intent.putExtra(IMAGE_PATH, holder.imagePath);
        intent.putExtra(TITLE, holder.title);
        intent.putExtra(DESCRIPTION, holder.description);

        startActivity(intent);
    }
}
